package com.techysky.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

@Configuration
public class IetmConfig extends WebMvcConfigurerAdapter{
	private static final String FILE = "file:";
	@Value("${img.path}")
    private String imgPath;
    @Value("${xml.path}")
    private String xmlPath;
    @Value("${xsl.path}")
    private String xslPath;
    @Value("${html.path}")
    private String htmlPath;
    @Value("${file.path}")
    private String filePath;
    @Value("${paper.path}")
    private String paperPath;
    @Value("${paper.content}")
    private String paperContent;
  
	@Override
	public void addResourceHandlers(ResourceHandlerRegistry registry) {
		registry.addResourceHandler("/ietm/css/**").addResourceLocations("classpath:/static/ietm/css/");
		registry.addResourceHandler("/ietm/images/**").addResourceLocations("classpath:/static/ietm/images/");
		registry.addResourceHandler("/jqueryTreeview/**").addResourceLocations("classpath:/static/jqueryTreeview/");
		registry.addResourceHandler("/ietm/js/**").addResourceLocations("classpath:/static/ietm/js/");
		registry.addResourceHandler("/css/**").addResourceLocations("classpath:/static/css/");
		registry.addResourceHandler("/js/**").addResourceLocations("classpath:/static/js/");
		registry.addResourceHandler("/img/**").addResourceLocations("classpath:/static/img/");
		registry.addResourceHandler("/html/*").addResourceLocations(FILE+htmlPath);
		registry.addResourceHandler("/ietm/img/**").addResourceLocations(FILE+imgPath);
		registry.addResourceHandler("/xml/**").addResourceLocations(FILE+xmlPath);
		registry.addResourceHandler("/html/**").addResourceLocations(FILE+htmlPath);
		registry.addResourceHandler("/file/**").addResourceLocations(FILE+filePath);
		registry.addResourceHandler("/help/**").addResourceLocations("classpath:/static/help/");
		super.addResourceHandlers(registry);
	}

	public String getImgPath() {
		return imgPath;
	}

	public void setImgPath(String imgPath) {
		this.imgPath = imgPath;
	}

	public String getXmlPath() {
		return xmlPath;
	}

	public void setXmlPath(String xmlPath) {
		this.xmlPath = xmlPath;
	}

	public String getXslPath() {
		return xslPath;
	}

	public void setXslPath(String xslPath) {
		this.xslPath = xslPath;
	}

	public String getHtmlPath() {
		return htmlPath;
	}

	public void setHtmlPath(String htmlPath) {
		this.htmlPath = htmlPath;
	}

	public String getFilePath() {
		return filePath;
	}

	public void setFilePath(String filePath) {
		this.filePath = filePath;
	}

	public String getPaperPath() {
		return paperPath;
	}

	public void setPaperPath(String paperPath) {
		this.paperPath = paperPath;
	}

	public String getPaperContent() {
		return paperContent;
	}

	public void setPaperContent(String paperContent) {
		this.paperContent = paperContent;
	}

	@Override
	public void addCorsMappings(CorsRegistry registry) {
		registry.addMapping("/**").allowedMethods("*").allowedOrigins("*").allowedHeaders("*");
		super.addCorsMappings(registry);
	}


}
